<%doc>
Html fragments included from templates.
</%doc>

<%def name="calendar(cal)">
    <%doc>
    Month calendar.

    ``cal``
        xtreg.models.xplanner.Month
    </%doc>
    <%!
        import datetime
        def format_year_month(year, month):
            ym = datetime.date(year, month, 1)
            return ym.strftime('%B %Y')
        def format_month_short(year, month):
            ym = datetime.date(year, month, 1)
            return ym.strftime('%b')
        def this_month():
            return datetime.date.today().month
        def this_year():
            return datetime.date.today().year
    %>

<div class="xtreg-calendar">
    <%
        year, month = cal.id
    %>
    <div class="xtreg-summary">
        <div class="xtreg-month-num">${format_year_month(year, month)}</div>
        <div class="xtreg-month-stat">Total: ${h.number_with_precision(cal.value, 2)} h</div>
    </div>

    <div class="xtreg-nav">
        <table>
            <tr>
                <td>Go to:</td>
                <td>
                    <ul>
                        <li class="xtreg-today">${h.link_to_unless_current('Current month', h.url(year=this_year(), month=this_month()))}</li>
                    </ul>
                    <ul>
                        <li class="xtreg-year">${h.link_to(year-1, h.url(year=year-1, month=12))}</li>
% for m in range(1, 13):
                        <li class="xtreg-month">${h.link_to_unless_current(format_month_short(year, m), h.url(year=year, month=m))}</li>
% endfor
                        <li class="xtreg-year">${h.link_to(year+1, h.url(year=year+1, month=1))}</li>
                    </ul>
                </td>
            </tr>
        </table>
        <div class="xtreg-clear"></div>
    </div>

    <div class="xtreg-body">
        <table class="xtreg-calendar">
            <tr>
                <th></th>
                <th>Mo</th>
                <th>Tue</th>
                <th>We</th>
                <th>Th</th>
                <th>Fri</th>
                <th>Sa</th>
                <th>Su</th>
            </tr>
% for week in cal.substats:
            <tr>
                <td>
                    <div class="xtreg-week-num">week ${week.id + 1}</div>
                    <div class="xtreg-week-stat">${h.number_with_precision(week.value, 2)} h</div>
                </td>
%     for day in week.substats:
                <td>
%         if day is not None:
                    <div class="xtreg-day-num">${day.id.strftime('%d')}</div>
                    <div class="xtreg-day-stat">${h.number_with_precision(day.value, 2)} h</div>
%         endif
                </td>
%     endfor
            </tr>
% endfor
        </table>
    </div>
</div>
</%def>

<%def name="time_entry_list(time_entries, person)">
    <%doc>
    List of time entries.

    ``time_entries``
        List of TimeEntry
    ``person``
        Person
    </%doc>

    <div class="xtreg-time-entry-list`">
% if not time_entries:
No time entries.
% else:
        <ul class="xtreg-list">
%     for te in time_entries:
<%
    if person == te.person1:
        other = te.person2
    else:
        other = te.person1
%>
            <li>${te.report_date.date()} (${h.number_with_precision(te.duration, 2)} h): 
                ${h.link_to(te.task.name, h.url(controller='task', action='detail', id=te.task.id))}
%         if other is not None:
                (with ${h.link_to(other.name, h.url(id=other.id))})
%         endif
            </li>
%     endfor
        </ul>
% endif
    </div>
</%def>

<%def name="component(title)">
    <%doc>
    Wraps some HTML in a component div.

    ``title``
        Title of the component.
    </%doc>
    <div class="xtreg-component">
        <div class="xtreg-component-header">
        ${title}
        </div>
        <div class="xtreg-component-body">
            ${caller.body()}
        </div>
    </div>
</%def>

